package com.xiaomazi.ucenter.controller;

import com.xiaomazi.common.utils.JwtUtils;
import com.xiaomazi.common.utils.R;
import com.xiaomazi.servicebase.entity.UserInfo;
import com.xiaomazi.servicebase.entity.UserInfoToOrder;
import com.xiaomazi.ucenter.dto.LoginDTO;
import com.xiaomazi.ucenter.dto.RegisterDTO;
import com.xiaomazi.ucenter.entity.Ucenter;
import com.xiaomazi.ucenter.service.UcenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: llxy-parent
 * @description: 用户前端控制器
 * @author: 小马子
 * @create: 2023-02-28 11:43
 **/
@RestController
@RequestMapping("/educenter/member")
public class UcenterController {

    @Autowired
    private UcenterService ucenterService;


    @PostMapping("/login")
    public R login(@RequestBody LoginDTO loginDTO){
        return ucenterService.login(loginDTO);
    }

    @PostMapping("/register")
    public R register(@RequestBody RegisterDTO registerDTO){
        return ucenterService.register(registerDTO);
    }

    @GetMapping("/getUserInfo")
    public R getUserInfo(HttpServletRequest request){
        return R.ok().data("userInfo",ucenterService.getById(JwtUtils.getMemberIdByJwtToken(request)));
    }

    @GetMapping("/getUserInfoByUserId/{userId}")
    public UserInfo getUserInfoByUserId(@PathVariable String userId){
        return ucenterService.getUserInfoByUserId(userId);
    }

    @GetMapping("/getUserInfoToOrderByUserId/{userId}")
    public UserInfoToOrder getUserInfoToOrderByUserId(@PathVariable String userId){
        return ucenterService.getUserInfoToOrderByUserId(userId);
    }

    @GetMapping("/getCountByDay/{day}")
    public Integer getCountByDay(@PathVariable String day){
        return ucenterService.getCountByDay(day);
    }

}
